home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / TC / DRVRFUNC.C next >
Encoding:
C/C++ Source or Header  |  1993-10-26  |  14.9 KB  |  506 lines

  1. #include <dos.h>
  2. #include <string.h>
  3. #include "drvrfunc.h"
  4.  
  5. int SIMint;  // Interrupt used to access SBSIM
  6.  
  7. /*--- SBSIM error messages ------------------*/
  8. char *errorMsg[] = {NULL,
  9.             "SBSIM currently in use",
  10.             "Bad driver specified",
  11.             "Bad function specified",
  12.             "Voice process is already active",
  13.             "Couldn't start CT-VOICE",
  14.             "Couldn't start CTVDSK",
  15.             "Invalid SBSIM handle",
  16.             "Buffer not initialized yet",
  17.             "Bad file name for load",
  18.             "Bad file handle",
  19.             "Driver not started yet",
  20.             "XMS driver not installed",
  21.             "No free SBSIM handles",
  22.             "Bad file type specified",
  23.             "Couldn't free XMS block",
  24.             "Invalid source selected",
  25.             "Get-Pan-Position failed",
  26.             "Set-Pan-Position failed",
  27.             "Set-Volume failed",
  28.             "Couldn't start fade/pan",
  29.             "Couldn't stop fade/pan",
  30.                 "Couldn't pause fade/pan",
  31.             "Not a fade/pan operation",
  32.             "Bad mode for fade/pan",
  33.                 "Couldn't start fade/pan",
  34.             "Source not fading/panning",
  35.                 "FM or MIDI already playing",
  36.                 "Bad MIDI mapper format"};
  37.  
  38. /*************************************************************************
  39. *
  40. * FUNCTION: FINDDVR - Searches for the requested driver's interrupt number
  41. *                     by looking for IDStr (in theis case it will be
  42. *                     SBSIM) in the interrupt vector table memory at the
  43. *                     offset (as in SEGMENT:OFFSET) location passed to
  44. *                     this function.
  45. *
  46. * Inputs: IDStr - driver ID string (i.e. "SBSIM").
  47. *         IDOff - driver's ID offset.
  48. *
  49. * Output: interrupt number or 0 (error condition) if not found.
  50. *
  51. *************************************************************************/
  52. unsigned FindDvr(char *IDStr, unsigned int IDOff)
  53. {
  54.     unsigned dvrInt,
  55.     intFound = FALSE;
  56.     char far *far *dvrVec;
  57.  
  58.     for(dvrInt = 0x80; (dvrInt < 0x0C0) && (intFound == FALSE); ++ dvrInt)
  59.   {
  60.     dvrVec = MK_FP(0, dvrInt * 4);
  61.     if(!_fstrncmp((char far *)MK_FP(FP_SEG(*dvrVec), IDOff), IDStr,
  62.        sizeof(IDStr)))
  63.     {
  64.       intFound = TRUE;
  65.     }
  66.   }
  67.  
  68.   if(intFound == TRUE)
  69.     return(--dvrInt);
  70.  
  71.   return(0);
  72. }
  73.  
  74. /*************************************************************************
  75. *
  76. * FUNCTION: GETDVRINFO - Get status, entry point, buffer location, and
  77. *                        buffer size from SBSIM.  The DVRINFO struct gets
  78. *                        loaded with this information
  79. *
  80. * Inputs: driver - driver to get info on.
  81. *         *dvrInfo - pointer to DVRINFO structure.
  82. *
  83. * Output: status - the driver's status.
  84. *
  85. * note: requires SIMint be defined before calling.
  86. *
  87. *************************************************************************/
  88. int GetDvrInfo(DRIVER driver, DVRINFO *dvrInfo)
  89. {
  90.   int dvrLoc;
  91.  
  92.   dvrLoc = 1 << driver;
  93.   if(GetDrvrs() & dvrLoc)
  94.   {
  95.         dvrInfo->status = LOADED;
  96.         GetAddress(driver, &dvrInfo->entry);
  97.     if(GetBufInfo(driver, &dvrInfo->bufLoc, &dvrInfo->bufSize) != SIMerr_NoErr)
  98.     {
  99.       dvrInfo->bufLoc = 0;
  100.       dvrInfo->bufSize = 0;
  101.     }
  102.   }
  103.   else
  104.     dvrInfo->status = MISSING;
  105.  
  106.   return(dvrInfo->status);
  107. }
  108.  
  109. /*************************************************************************
  110. *
  111. * FUNCTION: VERSION - Get the current version of SBSIM.
  112. *
  113. * Inputs: none
  114. *
  115. * Output: version = high byte, sub-version = low byte.
  116. *
  117. * note: requires SIMint be defined before calling.
  118. *
  119. *************************************************************************/
  120. unsigned Version(void)
  121. {
  122.   union REGS inregs,
  123.          outregs;
  124.  
  125.   inregs.h.bh = 0;  // control function
  126.   inregs.h.bl = 0;  // query version sub-fn
  127.     int86(SIMint, &inregs, &outregs);
  128.   return(outregs.x.ax); // return version number
  129. }
  130.  
  131. /*************************************************************************
  132. *
  133. * FUNCTION: GETDRVRS - Determines which drivers are loaded.
  134. *
  135. * Inputs: none
  136. *
  137. * Output: bit field indicating which drivers are loaded.
  138. *
  139. *         bit 0 - FM driver
  140. *         bit 1 - Double disk buffered voice driver
  141. *         bit 2 - Memory voice driver
  142. *         bit 3 - Auxiliary driver (mixer)
  143. *         bit 4 - MIDI driver
  144. *
  145. * note: requires SIMint be defined before calling.
  146. *
  147. *************************************************************************/
  148. unsigned GetDrvrs(void)
  149.  {
  150.    union REGS inregs, outregs;
  151.  
  152.    inregs.h.bh = 0;  // control function
  153.    inregs.h.bl = 1;  // query drivers sub-fn
  154.    int86(SIMint, &inregs, &outregs);
  155.    return(outregs.x.ax);  // return driver bit field
  156. }
  157.  
  158. /*************************************************************************
  159. *
  160. * FUNCTION: GETADDRESS - Returns selected driver's entry address.
  161. *
  162. * Inputs: driver   0 - FM driver
  163. *                  1 - Double disk buffered voice driver
  164. *                  2 - Memory voice driver
  165. *                  3 - Auxiliary driver (mixer)
  166. *                  4 - MIDI driver
  167. *                  *address - storage for entry address pointer
  168. *
  169. * Output: 0 if no error.
  170. *
  171. * note: requires SIMint be defined before calling.
  172. *
  173. *************************************************************************/
  174. SIMERR GetAddress(DRIVER driver, long *address)
  175. {
  176.     union REGS inregs, outregs;
  177.  
  178.     inregs.h.bh = 0;  // control function
  179.     inregs.h.bl = 2;  // driver entry address sub-fn
  180.     inregs.x.ax = driver;
  181.     int86(SIMint, &inregs, &outregs);
  182.     *address = (long)MK_FP(outregs.x.dx, outregs.x.ax); // return address
  183.     if(!outregs.x.cflag)      // test for errors
  184.         return(0);            // return result
  185.  
  186.     return(outregs.x.ax); // error occured
  187. }
  188.  
  189. /*************************************************************************
  190. *
  191. * FUNCTION: GETBUFINFO - Returns selected driver's buffer address.
  192. *
  193. * Inputs: driver   0 - FM driver
  194. *                  1 - Double disk buffered voice driver
  195. *                  4 - MIDI driver
  196. *                  *address - pointer to storage for buffer address pointer
  197. *                  *size - pointer storage for size of buffer (in Kbytes)
  198. *
  199. * Output: 0 if no error
  200. *
  201. * note: requires SIMint be defined before calling.
  202. *
  203. *************************************************************************/
  204. SIMERR GetBufInfo(DRIVER driver, long *address, unsigned *size)
  205. {
  206.     union REGS inregs, outregs;
  207.  
  208.     inregs.h.bh = 0;  // control function
  209.     inregs.h.bl = 5;  // driver entry address sub-fn
  210.     inregs.x.ax = driver;
  211.     int86(SIMint, &inregs, &outregs);
  212.   *address = (long)MK_FP(outregs.x.dx, outregs.x.ax); // return address
  213.   *size = outregs.x.cx;  // return buffer size
  214.   if(!outregs.x.cflag)     // test for errors
  215.         return(0);           // No error
  216.  
  217.   return(outregs.x.ax);  // error occured
  218. }
  219.  
  220. /*************************************************************************
  221. *
  222. * FUNCTION: STARTSND - Initializes the driver for output.
  223. *
  224. * Inputs: driver:  0 - FM driver
  225. *                  1 - Double disk buffered voice driver
  226. *                  2 - Memory voice driver
  227. *                  4 - MIDI driver
  228. *               *ptr - pointer to filename or memory location.
  229. *
  230. *         type: EXTENDED_MEM_VOD - Play a .VOC file from extended
  231. *                                                                     memory.  #defined in DVRVFUNC.H
  232. *
  233. *               NULL - Anything except a .VOC file from extended memory
  234. *
  235. * Output: Initialization result
  236. *
  237. * note: requires SIMint be defined before calling.
  238. *
  239. *************************************************************************/
  240. SIMERR StartSnd(DRIVER driver, void far *ptr, char type, int SBSIMHandle)
  241. {
  242.   union REGS inregs, outregs;
  243.  
  244.   inregs.h.bh = driver + 1;
  245.   inregs.h.bl = 0;            // start sound source function
  246.   inregs.x.cx = 0;
  247.   if (type == EXTENDED_MEM_VOC)
  248.   {
  249.     inregs.x.ax = SBSIMHandle;
  250.     inregs.x.dx = 0;
  251.   }
  252.     else  //  NOT EXTENDED MEMORY .VOC FILE
  253.     {
  254.     inregs.x.ax = FP_OFF(ptr);  // pointer to filename or data buffer
  255.     inregs.x.dx = FP_SEG(ptr);
  256.   }
  257.   int86(SIMint, &inregs, &outregs);
  258.   return(outregs.x.ax);       // return initialization result
  259. }
  260.  
  261. /*************************************************************************
  262. *
  263. * FUNCTION: GETSNDSTAT - Get the driver's status.
  264. *
  265. * Inputs: driver   0 - FM driver
  266. *                  1 - Double disk buffered voice driver
  267. *                  2 - Memory voice driver
  268. *                  4 - MIDI driver
  269. *
  270. * Output: Current status
  271. *
  272. * note: requires SIMint be defined before calling.
  273. *
  274. * RETURNS: -1 (negative one) if still playing
  275. *           0 (zero) if done playing
  276. *
  277. *************************************************************************/
  278. unsigned GetSndStat(DRIVER driver)
  279. {
  280.   union REGS inregs, outregs;
  281.  
  282.     inregs.h.bh = driver + 1;
  283.   inregs.h.bl = 5;       // get sound status function
  284.   inregs.x.cx = 0;
  285.   int86(SIMint, &inregs, &outregs);
  286.   return(outregs.x.ax);  // return status
  287. }
  288.  
  289. /*************************************************************************
  290. *
  291. * FUNCTION: PLAYSND - Plays music/voice on the selected driver.
  292. *
  293. * Inputs: driver   0 - FM driver
  294. *                  1 - Double disk buffered voice driver
  295. *                  2 - Memory voice driver
  296. *                  4 - MIDI driver
  297. *
  298. * Output: Result
  299. *
  300. * note: requires SIMint be defined before calling.
  301. *
  302. *************************************************************************/
  303. SIMERR PlaySnd(DRIVER driver)
  304. {
  305.   union REGS inregs, outregs;
  306.  
  307.   inregs.h.bh = driver + 1;
  308.   inregs.h.bl = 1;      // play sound function
  309.     inregs.x.cx = 0;
  310.     int86(SIMint, &inregs, &outregs);
  311.     return(outregs.x.ax); // return result
  312. }
  313.  
  314. /*************************************************************************
  315. *
  316. * FUNCTION: STOPSND - Stops music/voice on the selected driver.
  317. *
  318. * Inputs: driver   0 - FM driver
  319. *                  1 - Double disk buffered voice driver
  320. *                  2 - Memory voice driver
  321. *                  4 - MIDI driver
  322. *
  323. * Output: none
  324. *
  325. * note: requires SIMint be defined before calling.
  326. *
  327. *************************************************************************/
  328. void StopSnd(DRIVER driver)
  329. {
  330.     union REGS inregs, outregs;
  331.  
  332.     inregs.h.bh = driver + 1;
  333.     inregs.h.bl = 2;   // stop sound function
  334.     inregs.x.cx = 0;
  335.     int86(SIMint, &inregs, &outregs);
  336. }
  337.  
  338. /*************************************************************************
  339. *
  340. * FUNCTION: PAUSESND - Pauses music/voice on the selected driver.
  341. *
  342. * Inputs: driver   0 - FM driver
  343. *                  1 - Double disk buffered voice driver
  344. *                  2 - Memory voice driver
  345. *                  4 - MIDI driver
  346. *
  347. * Output: None
  348. *
  349. * note: requires SIMint be defined before calling.
  350. *
  351. *************************************************************************/
  352. void PauseSnd(DRIVER driver)
  353. {
  354.   union REGS inregs, outregs;
  355.  
  356.   inregs.h.bh = driver + 1;
  357.   inregs.h.bl = 3;    // pause sound function
  358.   inregs.x.cx = 0;
  359.   int86(SIMint, &inregs, &outregs);
  360. }
  361.  
  362. /*************************************************************************
  363. *
  364. * FUNCTION: RESUMESND - Continues paused music/voice.
  365. *
  366. * Inputs: driver   0 - FM driver
  367. *                  1 - Double disk buffered voice driver
  368. *                  2 - Memory voice driver
  369. *                  4 - MIDI driver
  370. *
  371. * Output: none
  372. *
  373. * note: requires SIMint be defined before calling.
  374. *
  375. *************************************************************************/
  376. void ResumeSnd(DRIVER driver)
  377. {
  378.   union REGS inregs, outregs;
  379.  
  380.   inregs.h.bh = driver + 1;
  381.   inregs.h.bl = 4;  // resume sound function
  382.   inregs.x.cx = 0;
  383.   int86(SIMint, &inregs, &outregs);
  384. }
  385.  
  386. /*************************************************************************
  387. *
  388. * FUNCTION: GETVOLUME - Get the source's volume.
  389. *
  390. * Inputs: source  0 - Master volume
  391. *                 1 - Voice volume
  392. *                 2 - MIDI volume
  393. *                 3 - CD volume
  394. *                 4 - Line-in volume
  395. *                 5 - Microphone volume
  396. *           *volume - source's volume returned in this variable
  397. *
  398. * Output: 0 if no error
  399. *
  400. * note: requires SIMint be defined before calling.
  401. *
  402. *************************************************************************/
  403. SIMERR GetVolume(SOURCE source, unsigned *volume)
  404. {
  405.   union REGS inregs, outregs;
  406.  
  407.   inregs.x.ax = source;
  408.     inregs.h.bh = 4;  // auxilary function
  409.   inregs.h.bl = 0;  // get source volume sub-function
  410.   int86(SIMint, &inregs, &outregs);
  411.   *volume = outregs.x.ax;  // return volume
  412.   if(outregs.x.cflag)
  413.     return(outregs.x.ax);  // return error code
  414.   return(0);
  415. }
  416.  
  417. /*************************************************************************
  418. *
  419. * FUNCTION: SETVOLUME - Set the source's volume.
  420. *
  421. * Inputs: source  0 - Master volume
  422. *                 1 - Voice volume
  423. *                 2 - FM volume
  424. *                 3 - CD volume
  425. *                 4 - Line-in volume
  426. *                 5 - Microphone volume
  427. *            volume - source's new volume
  428. *
  429. * Output: 0 if no error
  430. *
  431. * note: requires SIMint be defined before calling.
  432. *
  433. *************************************************************************/
  434. SIMERR SetVolume(SOURCE source, unsigned volume)
  435. {
  436.   union REGS inregs, outregs;
  437.  
  438.   inregs.h.bh = 4;  // auxilary function
  439.   inregs.h.bl = 1;  // set source volume sub-function
  440.   inregs.x.ax = source;
  441.   inregs.x.dx = volume;
  442.   int86(SIMint, &inregs, &outregs);
  443.     return(outregs.x.ax);
  444. }
  445.  
  446.  
  447. /*************************************************************************
  448. *
  449. *
  450. * FUNCTION: LoadExtMem() - Load a .VOC file into extended memory.
  451. *
  452. * DESCRIPTION:  The parameter passed is far pointer to a null terminated
  453. *               string that contains the filename to be loaded into
  454. *               extended memory. (Example:  C:\VOICE\TEST.VOC)
  455. *
  456. *
  457. *
  458. * RETURNS: If successful, the SBSIM handle to extended memory will be
  459. *          returned.  (This handle will be used by FreeExtMem() to free
  460. *          the memory.)  If not successful, an SIMERR type will be
  461. *          returned.
  462. *
  463. *************************************************************************/
  464. SIMERR LoadExtMem(void far *Ptr)
  465. {
  466.   union REGS inregs, outregs;
  467.  
  468.   inregs.x.dx = FP_OFF(Ptr);
  469.   inregs.x.ax = FP_SEG(Ptr);    // Load DS register via AX register
  470.   asm {
  471.     mov ds, ax
  472.       }
  473.  
  474.   inregs.h.bh = 0;
  475.   inregs.h.bl = 16;
  476.   inregs.x.ax = 0;
  477.   inregs.x.cx = 0;  // Have driver assign you a handle (returned in AX)
  478.   int86(SIMint, &inregs, &outregs);
  479.  
  480.   return(outregs.x.ax);  // return extended mem. handle
  481. }
  482.  
  483. /*************************************************************************
  484. *
  485. *
  486. * FUNCTION: FreeExtMem() - Releases the memory in extended memory.
  487. *
  488. * DESCRIPTION: Pass the SBSIMHandle obtained by LoadExtMem() to this
  489. *              function.  The extended memory used by the LoadExtMem()
  490. *              will then be freed.
  491. *
  492. * RETURNS: 0 - (zero) if there are NO errors.  Otherwise a SIMERR type
  493. *              will be returned.
  494. *
  495. *************************************************************************/
  496. SIMERR FreeExtMem(int SBSIMHandle)
  497. {
  498.   union REGS inregs, outregs;
  499.  
  500.   inregs.h.bh = 0;
  501.   inregs.h.bl = 19;
  502.   inregs.x.ax = SBSIMHandle;
  503.   int86(SIMint, &inregs, &outregs);
  504.  
  505.   return(outregs.x.ax);  // return result
  506. }